package com.weayer.controller;

import com.weayer.dto.OrderInfo;
import com.weayer.dto.ResponseResult;
import com.weayer.request.DriverGrabRequest;
import com.weayer.request.OrderRequest;
import com.weayer.service.GrabService;
import com.weayer.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: Service服务 - 订单 - 订单Controller
 * @author: Weayer
 **/
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;

    @Autowired
//    @Qualifier("diyRedisGrabService")
//    @Qualifier("redissonGrabService")
    @Qualifier("redissonYamlService")
//    @Qualifier("redissonMasterGrabService")
//    @Qualifier("redissonSentinelService")
    GrabService grabService;

    @PostMapping("/add")
    public ResponseResult add(@RequestBody OrderRequest orderRequest, HttpServletRequest httpServletRequest){
        // 网关添加header
//        String deviceCode = httpServletRequest.getHeader(HeaderParamConstants.DEVICE_CODE);
//        orderRequest.setDeviceCode(deviceCode);

        return orderInfoService.add(orderRequest);
    }

    @PostMapping("/book")
    public ResponseResult book(@RequestBody OrderRequest orderRequest, HttpServletRequest httpServletRequest){
        return orderInfoService.book(orderRequest);
    }

    @PostMapping("/grab")
    public ResponseResult driverGrab(@RequestBody DriverGrabRequest driverGrabRequest){
//        return orderInfoService.grab(driverGrabRequest);
        return grabService.grab(driverGrabRequest);
    }

    @PostMapping("/to-pick-up-passenger")
    public ResponseResult changeStatus(@RequestBody OrderRequest orderRequest){
        return orderInfoService.toPickUpPassenger(orderRequest);
    }

    @PostMapping("/arrived-departure")
    public ResponseResult arrivedDeparture(@RequestBody OrderRequest orderRequest){
        return orderInfoService.arrivedDeparture(orderRequest);
    }

    @PostMapping("/pick-up-passenger")
    public ResponseResult pickUpPassenger(@RequestBody OrderRequest orderRequest){
        return orderInfoService.pickUpPassenger(orderRequest);
    }

    @PostMapping("/passenger-getoff")
    public ResponseResult passengerGetoff(@RequestBody OrderRequest orderRequest){
        return orderInfoService.passengerGetoff(orderRequest);
    }

    @GetMapping("/detail")
    public ResponseResult<OrderInfo> detail(Long orderId){
        return orderInfoService.detail(orderId);
    }

    @GetMapping("/current")
    public ResponseResult current(String phone , String identity){
        return orderInfoService.current(phone , identity);
    }
}
